package Test;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

//键盘监听
public class MyJfram3 extends JFrame implements KeyListener {
    public MyJfram3(){
        this.setSize(600,500);
        this.setTitle("拼图");
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setLayout(null);

        //给整个窗体添加键盘监听
        addKeyListener(this);
        this.setVisible(true);

    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {
//        System.out.println("按压");
        int keycode = e.getKeyCode();
//        System.out.println(keycode);
    }

    @Override
    public void keyReleased(KeyEvent e) {
//        System.out.println("释放");
        int keycode = e.getKeyCode();
        if (keycode == 65){
            System.out.println("你松开的是a");
        } else if (keycode == 66) {
            System.out.println("你松开的是b");
        }
    }

}
